/**
*作者 ：王文成
*日期:2011-03-07
*Email: wellse@qq.com
*/

jQuery( function(){
	// 屏蔽选择功能
	jQuery(document.body).dblclick( function(event) {
		var pageId = jQuery("input[name=pageId]").val();
		if( event.ctrlKey && pageId){//ctrl键
			var url = ctx + "/page/config/queryPageEdit.do?id=" + pageId;
			Tools.window({args:window,width:950,height:650,url:url});
		}
	});
});


var Tools = {};

// 取得对象
var $E = function( id ){
	return document.getElementById(id) || null;
};

// 取得对象值
var $V = function( id ){
	return $A(id,"value")  ;
};

// 取得对象属性
var $A = function( id , attrName ){
	var element = $E(id);
	return element ? element[attrName] : null ;
};

// 对象是否有效，如果是字符串将判断是否为空
Tools.isValid = function( value ){
	if( value != null ){
		return value.toString().length > 0
	}
	return false;
};

// 执行方法
Tools.eval = function( script ){
	if(script == null ) return "";
	if( script.startWith("script:") ){
		var js = script.replace(/script\:/g,"");
		return (new Function(js))();
	}
	return script;
};

// JSON字符串转化对象
Tools.toObject = function(obj){  
	return (new Function("return " + obj + ";"))();
};

// 对象转化为JSON字符串
Tools.toJSON = function(obj){   
    switch(obj.constructor){   
		case Object:   
			var str = "{";   
			for(var o in obj){   
				var val = this.toJSON(obj[o]);
				if( typeof val != 'undefined' ){
					str += o + ":" + val +",";
				}
			}
			if(str.substr(str.length-1) == ",")   
				str = str.substr(0,str.length -1);   
			return str + "}";   
			break;   
		case Array:          
			var str = "[";   
			for(var o in obj){   
				var val = Tools.toJSON(obj[o]);
				if( typeof val != 'undefined' )
					str += val +",";   
			}   
			if(str.substr(str.length-1) == ",")
				str = str.substr(0,str.length -1);   
			return str + "]";   
			break;   
		case Boolean:   
			return "" + obj.toString() + "";   
			break;   
		case Date:   
			return "\"" + obj.toString() + "\"";   
			break;   
		case Function:   
			break;   
		case Number:   
			return "" + obj.toString() + "";   
			break;    
		case String:   
			return "\"" + obj.toString() + "\"";   
			break;       
    }   
};

Tools.window = function( option ){
	var url = option.url;
	var title = option.title || "";
	var status = option.status || "yes";
	var height = option.height || 600;
	var width = option.width || 800;
	var left = option.left || (screen.width-width)/2;
	var top = option.left || (screen.height-height)/2;
	var args = option.args != null ? option.args : window;
	var param = new String();
	param += 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',';
	param += 'location=no,directories=no,status=' + status + ',menubar=no,toolbar=no,resizable=no';
	//var win = window.open(option.url,title,param);
	window.showModalDialog(url,args,"center:1;dialogWidth:" + width + "px;dialogHeight:" + height + "px;scroll:0;help:0;status:1");
}
